#include <cppunit/config/SourcePrefix.h>
#include "Parent.h"
#include "TestParent.h"

#include <algorithm>
#include <iostream>
#include <string>

void ParentTest::setUp()
{
	cout << "Test PKB Parent setUp()\n";
}
void ParentTest::tearDown()
{}
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( ParentTest ); 
// method to test the constructor
void ParentTest::testConstructor() { 
// create a Follow object
// check that the object is constructed correctly
//	Parent myParentTable = Parent::Parent();
}
void ParentTest::testSetParent(){
	Parent myParentTable = Parent::Parent();
	myParentTable.setParent(1,2);
	CPPUNIT_ASSERT_EQUAL(2, myParentTable.getChild(1).back());
	CPPUNIT_ASSERT_EQUAL(1, myParentTable.getParent(2));
}
void ParentTest::testGetChild(){
	Parent myParentTable = Parent::Parent();
	myParentTable.setParent(1,2);
	myParentTable.setParent(1,3);
	myParentTable.setParent(1,4);
	myParentTable.setParent(4,5);
	myParentTable.setParent(5,6);

	std::vector<int> childList;

	childList = myParentTable.getChild(1);
	CPPUNIT_ASSERT_EQUAL(3, (int)childList.size());
	CPPUNIT_ASSERT_EQUAL(2, childList.at(0));
	CPPUNIT_ASSERT_EQUAL(3, childList.at(1));
	CPPUNIT_ASSERT_EQUAL(4, childList.at(2));

	childList = myParentTable.getChild(4);
	CPPUNIT_ASSERT_EQUAL(1, (int)childList.size());
	CPPUNIT_ASSERT_EQUAL(5, childList.at(0));

	childList = myParentTable.getChild(5);
	CPPUNIT_ASSERT_EQUAL(1, (int)childList.size());
	CPPUNIT_ASSERT_EQUAL(6, childList.at(0));
}
void ParentTest::testGetParent(){
	Parent myParentTable = Parent::Parent();
	myParentTable.setParent(1,2);
	CPPUNIT_ASSERT_EQUAL(1, myParentTable.getParent(2));
}
void ParentTest::testHasParent(){
	Parent myParentTable = Parent::Parent();
	myParentTable.setParent(1,2);
	CPPUNIT_ASSERT_EQUAL(true, myParentTable.hasParent(2));
}
void ParentTest::testHasChild(){
	Parent myParentTable = Parent::Parent();
	myParentTable.setParent(1,2);
	CPPUNIT_ASSERT_EQUAL(true, myParentTable.hasChild(1));
}
void ParentTest::testIsParent(){
	Parent myParentTable = Parent::Parent();
	myParentTable.setParent(1,2);
	CPPUNIT_ASSERT_EQUAL(true, myParentTable.isParent(1,2));
}
/*********************************
    ety c1 c2 c3 c4
 ety 0  0  0  0  0
 p1  0  0  1  0  0
 p2  0  0  0  1  1
 p3  0  0  0  0  0
 p4  0  0  0  0  0

 parent(1,2)
 parent(2,3)
 parent(2,4)
**********************************/
void ParentTest::testSetParentBitMap(){
	Parent myParentTable = Parent::Parent();
	myParentTable.setParent(1,2);
	myParentTable.setParent(2,3);
	myParentTable.setParent(2,4);
	CPPUNIT_ASSERT_EQUAL(false, myParentTable.isBitMapSet());
	vector<vector<bool>> sampleBitMap;
	for (int i = 0 ; i < 5; i++){
		vector<bool> temp;
		temp.clear();
		if (i==0 || i==3 || i==4 ){
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
		}else if(i==1){
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(true);
			temp.push_back(false);
			temp.push_back(false);
		}else{
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(false);
			temp.push_back(true);
			temp.push_back(true);
		}
		sampleBitMap.push_back(temp);
	}
	myParentTable.setParentBitMap(sampleBitMap);
	CPPUNIT_ASSERT_EQUAL(true, myParentTable.isBitMapSet());
	CPPUNIT_ASSERT_EQUAL(true, myParentTable.isParent(1,2));
	CPPUNIT_ASSERT_EQUAL(true, myParentTable.isParent(2,3));
	CPPUNIT_ASSERT_EQUAL(true, myParentTable.isParent(2,4));
	CPPUNIT_ASSERT_EQUAL(false, myParentTable.isParent(2,1));
	CPPUNIT_ASSERT_EQUAL(false, myParentTable.isParent(3,4));

}
